package com.dgut.finaldemo.controller;

import com.dgut.finaldemo.entity.StudentHealth;
import com.dgut.finaldemo.service.StudentHealthService;
import com.dgut.finaldemo.util.R;
import com.dgut.finaldemo.vo.DataVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller //走视图解析器
public class StudentHealthController {
    @Autowired
    private StudentHealthService studentHealthService;

    @RequestMapping("/studentHealth")
    @ResponseBody //直接返回json
    public DataVO studentList(Integer page,Integer limit){
        return studentHealthService.findData(page,limit);
    }

    @GetMapping("/studentHealthHtml")
    public String studentHealthHtml(){
        return "studentHealth";
    }

    @GetMapping("/studentDayHealthHtml")
    public String studentDayHealthHtml(){
        return "studentDayHealth";
    }

    @GetMapping("/{url}")
    public String redirect(@PathVariable("url") String url){
        return url;
    }

    @RequestMapping("/addStudentHealth")
    public String addStudentHealth(){
        return "addStudentHealth";
    }

    @RequestMapping("studentHealth/addStudentHealthSubmit")
    @ResponseBody
    public R addStudentHealthSubmit(StudentHealth studentHealth, Model model){
        Integer flag = studentHealthService.addStudentHealth(studentHealth);
        if(flag==1){
            model.addAttribute("MESSAGE","添加成功！");
        }else{
            model.addAttribute("MESSAGE","账号学号不一致！");
        }
        return R.ok();
    }

    @RequestMapping("studentHealth/updateStudentHealthSubmit")
    @ResponseBody
    public R updateStudentHealthSubmit(StudentHealth studentHealth){
        studentHealthService.updateStudentHealth(studentHealth);
        return R.ok();
    }

    @RequestMapping("studentHealth/deleteStudentHealthById")
    @ResponseBody
    public R deleteStudentHealthById(Integer hid){
        studentHealthService.deleteStudentHealthByHid(hid);
        return R.ok();
    }

    @RequestMapping("studentHealth/searchStudentHealth")
    @ResponseBody
    public DataVO searchStudentHealth(Integer page,Integer limit
            ,StudentHealth studentHealth,Float maxTemperature){
        System.out.println(studentHealth);
        return studentHealthService.searchStudentHealth(page, limit,studentHealth,maxTemperature);
    }

    @RequestMapping("/studentDayHealth")
    @ResponseBody
    public DataVO searchStudentHealthByDay(Integer page,Integer limit){
        return studentHealthService.searchStudentHealthByDay(page, limit);
    }



}
